package com.bankLogisticsSys.controller;

import java.io.File;
import java.sql.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.bankLogisticsSys.service.ManageMonitorService;
import com.bankLogisticsSys.util.ExcelExportUtil;
import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Record;

public class ManageMonitorController extends Controller {
	
	ManageMonitorService service = new ManageMonitorService();
	
	public void list(){
		render("/WEB-INF/content/monitor/list.html");
	}
	
	public void monitorList(){
		java.util.Date date = getParaToDate("searchDate",new java.util.Date(System.currentTimeMillis()));
		Date searchDate = new Date(date.getTime());
		String network = getPara("network");
		List<Record> monitorList = service.getMonitorList2(network, searchDate);
		int totalCount = monitorList.size();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", totalCount);
		map.put("rows", monitorList);
		renderJson(map);
	}
	
	public void export(){
		java.util.Date date = getParaToDate("searchDate",new java.util.Date(System.currentTimeMillis()));
		Date searchDate = new Date(date.getTime());
		String network = getPara("network");
		List<Record> monitorList = service.getMonitorList2(network, searchDate);
		
	        Map<String, String> titleData = new LinkedHashMap<String, String>();//标题，后面用到
	        titleData.put("network", "邮政网点");
	        titleData.put("pack", "封包");
	        titleData.put("receive", "接收");
	        titleData.put("accept", "验收");
	        titleData.put("abnormal", "异常");
	        titleData.put("explain", "异常说明");
	        File file = new File(ExcelExportUtil.getTitle());
	    file = ExcelExportUtil.saveFile(titleData, monitorList, file);
	    this.renderFile(file);
	}
}
